<template>
  <div class="aui-card-list">
    <uni-list-query-card :queryShow="queryShow" @query-click="getDataList()" @click="(e)=>{this.queryShow=e}"
      @searchReset="searchReset()">
      <el-col :span="5">
        <el-form-item :label="$t('logOperation.creatorName')">
          <el-input v-model="dataForm.creatorName" :placeholder="$t('logOperation.creatorName')" clearable></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="5">
        <el-form-item :label="$t('logOperation.status')">
          <el-select v-model="dataForm.status" :placeholder="$t('logOperation.status')" clearable>
            <el-option :label="$t('logOperation.status0')" :value="0"></el-option>
            <el-option :label="$t('logOperation.status1')" :value="1"></el-option>
          </el-select>
        </el-form-item>
      </el-col>
      <el-col :span="10">
        <el-form-item label="操作时间">
          <el-date-picker v-model="dataForm.bDate" type="date" :placeholder="$t('beginDate')" value-format="yyyy-MM-dd"
            style="width: 160px">
          </el-date-picker>
          -
          <el-date-picker v-model="dataForm.eDate" type="date" :placeholder="$t('endDate')" value-format="yyyy-MM-dd"
            style="width: 160px">
          </el-date-picker>
        </el-form-item>
      </el-col>
    </uni-list-query-card>
    <el-card shadow="never" class="aui-card-list-body">
      <vxe-toolbar :setting="{immediate:true}">
        <template v-slot:buttons>
        </template>
        <template v-slot:tools>
          <el-button icon="el-icon-refresh" @click="getDataList()" circle></el-button>
          <el-dropdown trigger="click" style="padding-left: 5px;" placement="bottom">
            <el-button icon="el-icon-download" circle>
            </el-button>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item icon="el-icon-bottom" @click.native="exportHandle(true)">导出当前页</el-dropdown-item>
              <el-dropdown-item icon="el-icon-download" @click.native="exportHandle()">全部导出
              </el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
          <!-- <el-button icon="el-icon-download" @click="$refs.xTable.openExport()" circle></el-button> -->
        </template>
      </vxe-toolbar>
      <div class="aui-card-list-body-table">
        <vxe-table :loading="dataListLoading" :data="dataList" ref="xTable" auto-resize remote-sort sync-resize
          @sort-change="dataListSortChangeHandle" class="vxe-table-element" style="width: 100%" max-height="auto">
          <vxe-table-column type="expand" align="right" width="50">
            <template v-slot:content="{ row, rowIndex }">
              <el-form label-position="left" class="demo-table-expand">
                <el-form-item :label="$t('logOperation.requestUri')" align="left">
                  <span>{{ row.requestUri }}</span>
                </el-form-item>
                <el-form-item :label="$t('logOperation.requestMethod')" align="left">
                  <span>{{ row.requestMethod }}</span>
                </el-form-item>
                <el-form-item :label="$t('logOperation.requestParams')" align="left">
                  <span>{{ row.requestParams }}</span>
                </el-form-item>
                <el-form-item :label="$t('logOperation.requestTime')" align="left">
                  <span>{{ `${row.requestTime}ms` }}</span>
                </el-form-item>
                <el-form-item :label="$t('logOperation.ip')" align="left">
                  <span>{{ row.ip }}</span>
                </el-form-item>
              </el-form>
            </template>
          </vxe-table-column>
          <vxe-table-column field="creatorName" title="logOperation.creatorName" width="150">
          </vxe-table-column>
          <vxe-table-column field="deptName" title="logOperation.deptName" align="center"></vxe-table-column>
          <vxe-table-column field="operation" title="logOperation.operation" width="150">
          </vxe-table-column>
          <vxe-table-column field="userAgent" title="logOperation.Browser">
            <template slot-scope="scope">
              {{ userAgent(scope.row.userAgent).browser }}
            </template>
          </vxe-table-column>
          <vxe-table-column field="userAgent" title="logOperation.OS">
            <template slot-scope="scope">
              {{ userAgent(scope.row.userAgent).os }}
            </template>
          </vxe-table-column>
          <vxe-table-column field="status" title="logOperation.status" sortable width="80" align="center">
            <template slot-scope="scope">
              <el-tag v-if="scope.row.status === 0" size="small" type="danger">{{ $t('logOperation.status0') }}</el-tag>
              <el-tag v-else size="small" type="success">{{ $t('logOperation.status1') }}</el-tag>
            </template>
          </vxe-table-column>
          <vxe-table-column field="createDate" title="logOperation.createDate" sortable width="140" align="center">
          </vxe-table-column>
        </vxe-table>
        <el-pagination :current-page="page" :page-sizes="[10, 20, 50, 100]" :page-size="limit" :total="total"
          layout="total, sizes, prev, pager, next, jumper" @size-change="pageSizeChangeHandle"
          @current-change="pageCurrentChangeHandle">
        </el-pagination>
      </div>
    </el-card>
  </div>
</template>

<style>
.demo-table-expand {
  font-size: 0;
}

.demo-table-expand label {
  width: 90px;
  color: #99a9bf;
}

.demo-table-expand .el-form-item {
  margin-right: 0;
  margin-bottom: 0;
  width: 90%;
}

.demo-table-expand .el-form-item span {
  word-wrap: break-word;
}

.el-card--log .el-table__expand-column {
  border-right-width: 0px;
}
</style>

<script>
import mixinViewModule from '@/mixins/view-module'
import { fnUserAgent } from '@/utils/ua'

export default {
  mixins: [mixinViewModule],
  data () {
    return {
      mixinViewModuleOptions: {
        getDataListURL: '/sys/log/operation/page',
        getDataListIsPage: true,
        exportURL: '/sys/log/operation/export'
      },
      dataForm: {
        creatorName: '',
        status: '',
        bDate: this.$formatDate(new Date()),
        eDate: null
      }
    }
  },
  methods: {
    // 识别设备
    userAgent (userAgent) {
      return fnUserAgent(userAgent)
    }
  }
}
</script>
